2.1.4 Consul安装与使用

准备工作

一台CentOS 7 机器,输入ifconfig ,查看网卡信息如下:

  1. eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
  2. inet 192.168.11.143 netmask 255.255.255.0 broadcast 192.168.11.255
  3. inet6 fe80::20c:29ff:fe89:6b91 prefixlen 64 scopeid 0x20<link>
  4. ether 00:0c:29:89:6b:91 txqueuelen 1000 (Ethernet)
  5. RX packets 752526 bytes 705406371 (672.7 MiB)
  6. RX errors 0 dropped 0 overruns 0 frame 0
  7. TX packets 142062 bytes 18646825 (17.7 MiB)
  8. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
  9. lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
  10. inet 127.0.0.1 netmask 255.0.0.0
  11. inet6 ::1 prefixlen 128 scopeid 0x10<host>
  12. loop txqueuelen 0 (Local Loopback)
  13. RX packets 172 bytes 1003766 (980.2 KiB)
  14. RX errors 0 dropped 0 overruns 0 frame 0
  15. TX packets 172 bytes 1003766 (980.2 KiB)
  16. TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

我们可以看到,该机器有两个IP:

  1. 192.168.11.143
  2. 127.0.0.1

Consul的安装与启动

  • 安装Consul(以CentOS7为例):
  1. cd /usr/local/bin/
  2. wget https://releases.hashicorp.com/consul/0.7.0/consul_0.7.0_linux_amd64.zip
  3. unzip consul0.7.0linux_amd64.zip

得到consul 文件,这样就完成了安装。

  • 启动Consul
  1. ./consul agent -dev # -dev表示开发模式运行,另外还有-server表示服务模式运行
  • 输入http://127.0.0.1:8500/ui/ 访问Consul,可查看到如下界面:

Consul4. 我们尝试访问http://192.168.11.143/ui/ ,会发现无法访问。说明Consul还不能被远程访问。那么如何设置才能被远程访问呢?Consul如何高可用呢?